package com.itmk.system.permission.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itmk.system.permission.entity.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {


    @Select("select p.id as id, p.name as name, p.url as url from  role_permission rp " +
            "left join permission p on rp.permission_id=p.id " +
            "where  rp.role_id= #{roleId} ")
    List<Permission> findPermissionListByRoleId(@Param("roleId") Long roleId);


    /**
     * 根据用户id查询用户权限
     * @param userId
     * @return
     */
    List<Permission> getPermissionListByUserId(@Param("userId") Long userId);


    @Delete("delete from role_permission where role_id=#{roleId}")
    Long deletePermissionByRoleId(@Param("roleId") Long roleId);

}
